/*
* Copyright (C) 2008-2009 J-P Nurmi jpnurmi@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* $Id: tabwidget.h 598 2010-06-04 18:55:08Z jpnurmi $
*/

#ifndef TABWIDGET_H
#define TABWIDGET_H

#include <QTabWidget>
#include <QPointer>
#include <QIcon>
#include <QList>
#if QT_VERSION >= 0x040600
#include <QSwipeGesture>
#endif // QT_VERSION

class TabWidget : public QTabWidget
{
    Q_OBJECT
    Q_PROPERTY(QIcon alertIcon READ alertIcon WRITE setAlertIcon)
    Q_PROPERTY(QIcon highlightIcon READ highlightIcon WRITE setHighlightIcon)

public:
    TabWidget(QWidget* parent = 0);

    QIcon alertIcon() const;
    void setAlertIcon(const QIcon& icon);

    QIcon highlightIcon() const;
    void setHighlightIcon(const QIcon& icon);

    QMovie* animation() const;
    void setAnimation(QMovie* animation);

    bool hasTabAlert(int index);
    void setTabAlert(int index, bool alert);

    bool hasTabHighlight(int index) const;
    void setTabHighlight(int index, bool highlight);

    bool hasTabAnimation(int index);
    void setTabAnimation(int index, bool animate);

#if QT_VERSION >= 0x040600
    void registerSwipeGestures(Qt::Orientation orientation);
    void unregisterSwipeGestures();
#endif // QT_VERSION

public slots:
    void moveToNextTab();
    void moveToPrevTab();

signals:
    void alertStatusChanged(bool active);
    void highlightStatusChanged(bool active);
    void animationStatusChanged(bool active);

protected:
#if QT_VERSION >= 0x040600
    bool event(QEvent* event);
    bool handleSwipeGesture(QSwipeGesture* gesture, QSwipeGesture::SwipeDirection direction);
#endif // QT_VERSION
    void tabInserted(int index);
    void tabRemoved(int index);

private slots:
    void alertTimeout();
    void updateFrame();

private:
    struct TabWidgetData
    {
        QIcon alertIcon;
        QIcon highlightIcon;
        QPointer<QMovie> animation;
        QList<int> alertIndexes;
        QList<int> highlightIndexes;
        QList<int> animationIndexes;
        Qt::Orientation swipeOrientation;
    } d;
};

#endif // TABWIDGET_H
